package com.binarysoft.service.common.ping;

import java.net.InetAddress;

import common.framework.dsb.client.DefaultServiceFactory;
import common.framework.dsb.client.ServiceFactory;

public class TestPing {

	public static void main(String[] args){
		ServiceFactory serviceFactory = new DefaultServiceFactory();
		try {
			PingService pingService = (PingService)serviceFactory.lookup("DSB/PingService", "132.159.156.190", 10000);
			Thread pingThread1 = new PingControlThread(pingService, "132.159.156.194");
			pingThread1.start();
			Thread pingThread2 = new PingControlThread(pingService, "132.159.156.191");
			pingThread2.start();
			Thread pingThread3 = new PingControlThread(pingService, "132.159.156.192");
			pingThread3.start();
			Thread pingThread4 = new PingControlThread(pingService, "132.159.156.193");
			pingThread4.start();
			Thread pingThread5 = new PingControlThread(pingService, "132.159.152.98");
			pingThread5.start();
			Thread pingThread6 = new PingControlThread(pingService, "132.159.152.98");
			pingThread6.start();
			Thread pingThread7 = new PingControlThread(pingService, "132.159.156.182");
			pingThread7.start();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

	
}


class PingControlThread extends Thread{
	PingService pingService = null;
	String ip;
	public PingControlThread(PingService pingService, String ip){
		this.pingService = pingService;
		this.ip = ip;
	}
	
	public void run(){
		try {
			for(int i=1; i<254; i++){
				new PingThread(pingService, "132.159.156."+i).start();
				
//				PingResult result = pingService.doPing(InetAddress.getByName(ip));
//				System.out.println(ip+" - "+result.isTimedout()+" "+result.getRtt()+" "+result.getTtl());
			}
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
	
}




class PingThread extends Thread{
	PingService pingService = null;
	String ip;
	public PingThread(PingService pingService, String ip){
		this.pingService = pingService;
		this.ip = ip;
	}
	
	public void run(){
		try {
			PingResult result = pingService.doPing(InetAddress.getByName(ip));
			System.out.println(this.ip+" - "+result.isTimedout()+" "+result.getRtt()+" "+result.getTtl());
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}
}
